﻿CREATE PROCEDURE [dbo].[yaf_forum_list](
                @BoardID INT,
                @ForumID INT  = NULL)
AS
    BEGIN
        IF @ForumID = 0
        SET @ForumID = NULL
        IF @ForumID IS NULL
        SELECT   a.*
        FROM     yaf_Forum a
                 JOIN yaf_Category b
                   ON b.CategoryID = a.CategoryID
        WHERE    b.BoardID = @BoardID
        ORDER BY a.SortOrder
        ELSE
        SELECT a.*
        FROM   yaf_Forum a
               JOIN yaf_Category b
                 ON b.CategoryID = a.CategoryID
        WHERE  b.BoardID = @BoardID
        AND a.ForumID = @ForumID
    END


